package com.milk.service.product;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;

import com.milk.model.entity.product.Product;
import com.milk.service.product.dao.ProductDao;

import org.springframework.stereotype.Service;

/**
 * product serviceImpl 2017-09-14 16:56:24 徐政涛
 */
@Service("productService")
public class ProductServiceImpl implements ProductService {

	@Autowired
	private ProductDao productDao;

	public Product save(Product product) {
		Assert.notNull(product, RESULT_NULL + "出错的方法体是saveProduct");
		productDao.save(product);
		return product;
	}

	public Product update(Product product) throws Exception {
		Assert.notNull(product, RESULT_NULL + "出错的方法体是updateProduct");
		productDao.update(product);
		return product;
	}

	public Product getProductById(long productId) {
		Product product = productDao.findById(productId);
		return product;
	}

	public void deleteProductById(long productId) {
		productDao.deleteById(productId);
	}

	public Product getProductByMap(Map<String, Object> params) {
		Product product = productDao.findByMap(params);
		return product;
	}

	public void deleteProductByMap(Map<String, Object> params) {
		productDao.deleteByMap(params);
	}

	public List<Product> queryProduct(Map<String, Object> params) {
		List<Product> products = productDao.query(params);
		return products;
	}
}